package com.preskool.service.impl;

import com.preskool.mapper.StudentMapper;
import com.preskool.mapper.TeacherMapper;
import com.preskool.po.Student;
import com.preskool.po.Teacher;
import com.preskool.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author kennyzzz
 * @Data 2021/1/8 11:21
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired(required = false)
    private StudentMapper studentMapper;
    @Autowired(required = false)
    private TeacherMapper teacherMapper;

    @Override
    public Object loginUser(String username, String password, Integer rid) {
        if(rid==1){
            Student student = studentMapper.selectStudentByUsername(username);
            if(student!=null){
                if(student.getPassword().equals(password)){
                    return  student;
                }else{
                    return null;
                }

            }


        }else if(rid==2){
            Teacher teacher = teacherMapper.selectTeacherByUsername(username);
            if(teacher!=null){
                if(teacher.getPassword().equals(password)){
                    return  teacher;
                }else{
                    return null;
                }

            }
        }
        return null;
    }

    @Override
    public boolean selectUserByEmail(String email) {
        if(teacherMapper.selectTeacherByEmail(email)!=null){
            return true;
        }
        if(studentMapper.selectStudentByEmail(email)!=null){
            return true;
        }
        return false;
    }
}
